#
# Copyright 2008 Charles Connell <charles@connells.org>
#
# This file is part of Recuerde.
#
# Recuerde is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Recuerde is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Recuerde; if not, see <http://gnu.org/licenses/.>
#

FIELDTYPE_STRING = 1
FIELDTYPE_DATE = 2
FIELDTYPE_CHOICE = 3

class Item:
    """Manages tasks."""
    def __init__(self, name=""):
        """Initializes values."""
        # Initialize values
        self.id = None
        self.properties = {}
        self.name = None
        self.list = None

    def SetName (self, name):
        self.name = name

    def GetName (self):
        return self.name

    def SetProperty (self, property, value):
        self.properties[property] = value

    def GetProperty (self, property):
        return self.properties[property]

    def GetList (self):
        return self.list

class List:
    """Manages tasks."""
    def __init__(self, name=""):
        """Initializes values."""
        # Initialize values
        self.name = name
        self.id = None
        self.fields = []
        self.items = []

    def AddField(self, type, name, choices=()):
        """Add a property to the list."""
        field = ()
        if type is FIELDTYPE_CHOICE:
            field = (type, name, choices)
        else:
            field = (type, name)
        self.fields.append(field)

    def SetFields(self, fields):
        self.fields = list(fields)

    def GetFields(self):
        return tuple(self.fields)

    def SetName(self, name):
        self.name = name

    def GetName(self):
        return self.name

    def AddItem(self, item):
        self.items.append(item)
        item.list = self

    def RemoveItem(self, item):
        self.items.remove(item)

    def GetItems(self):
        return self.items
